  //--------------------------------
  // Per Pixel Lighting
  //--------------------------------
  // By Evolved
  // http://www.vector3r.com/
  //--------------------------------

  //-----------------
  // un-tweaks
  //-----------------
   matrix WorldVP:WorldViewProjection; 
   matrix World:World;    

  //-----------------
  // tweaks
  //-----------------
   float4 Ambient   = {0.1f, 0.1f, 0.2f, 1.0f};    
   float4 LightPosition = {0.0f, 0.0f, 0.0f, 1.0f};    
   float4 LightColor = {0.0f, 0.0f, 0.0f, 1.0f};    
   float  LightRange = 0.0f;
   float U = 1.0f; 
   float V = 1.0f; 

  //-----------------
  // Textures
  //-----------------
   texture BaseTX
    <
	string Name="";
    >;	
   sampler2D Base = sampler_state 
    {
 	texture = <BaseTX>;
	MagFilter = None;
	MinFilter = None;
	MipFilter = None;
    };

  //-----------------
  // structs 
  //-----------------
   struct input
     {
 	float4 Pos:POSITION; 
 	float2 UV:TEXCOORD; 
	float3 Normal : NORMAL;
     };
   struct output
     {
	float4 OPos:POSITION; 
 	float2 Tex:TEXCOORD0;  
	float3 Attenuation:TEXCOORD1;
	float Diffuse:TEXCOORD2;
     };
   struct output0
     {
	float4 OPos:POSITION; 
 	float2 Tex:TEXCOORD0;  
	float3 Attenuation:TEXCOORD1;
	float Diffuse:TEXCOORD2;
	float3 Attenuation0:TEXCOORD3;
	float Diffuse0:TEXCOORD4;
     };

  //-----------------
  // vertex shader
  //-----------------
   output VS_L1(input IN) 
     {
 	output OUT;
	OUT.OPos=mul(IN.Pos,WorldVP); 
 	OUT.Tex=IN.UV*float2(U,V);
	float3 Wnor=mul(IN.Normal,World); 
	Wnor=normalize(Wnor);
	float3 WPos=mul(IN.Pos,World);  
	float3 LightPos=LightPosition-WPos; 
	OUT.Attenuation=LightPos/LightRange;
 	OUT.Diffuse=saturate(1.0f+mul(Wnor,LightPos)*1.0f); 
	return OUT;
     }

  //-----------------
  // pixel shader
  //-----------------
    float4 PS_L1(output IN)  : COLOR
     {
	float4 Texture=tex2D(Base,IN.Tex); 
	float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
	float4 Light=DiffuseLight*LightColor;
	return Texture*(Light+Ambient);
     }


  //-----------------
  // techniques   
  //-----------------
   technique Light1
      {
 	pass p1
      {		
 	vertexShader = compile vs_1_1 VS_L1(); 
 	pixelShader  = compile ps_1_4 PS_L1(); 	
      }
      }